
var baseIcon = new GIcon();
baseIcon.image = 'http://<?php echo WSB_HOST . WSB_URL ?>WSB/xtensions/sherpa/etc/GoogleMapIconSherpa.png';
baseIcon.iconSize = new GSize(31, 29);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);

function loadGoogleMap() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(47.341361, 7.908931), 8);

    GDownloadUrl("<?php echo $this->urlThisPage(array('sherpa' => array('action' => 'xml'))) ?>", function(data) {
      var xml = GXml.parse(data);
      var markers = xml.documentElement.getElementsByTagName("marker");
      for (var i = 0; i < markers.length; i++) {
        var html = markers[i].firstChild.data;
        var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                parseFloat(markers[i].getAttribute("lng")));
        var marker = createMarker(point, html);
        map.addOverlay(marker);
      }
    });
  }
}

function createMarker(point, html) {
  var marker = new GMarker(point, baseIcon);
  GEvent.addListener(marker, 'click', function() {
    marker.openInfoWindowHtml(html);
  });
  return marker;
}

function goToStore(select)
{
    var index = select.selectedIndex;
    if(index > 0) {
        var url = select.options[index].value;
        if(url != '') {
            window.location.href = url;
        }
    }
}

window.onload = loadGoogleMap;
